package com.retail.order.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.retail.core.entity.enums.DelFlagEnum;
import com.retail.core.entity.enums.StatusFlagEnum;
import com.retail.core.entity.result.Result;
import com.retail.msg.entity.request.RetailMsgRequest;
import com.retail.msg.enums.MsgTypeEnums;
import com.retail.msg.service.RetailMsgService;
import com.retail.order.entity.request.AdminVerifyDetailOrderRequest;
import com.retail.order.entity.request.SysAdminVerifyDetailRequest;
import com.retail.order.entity.vo.*;
import com.retail.core.entity.ParamReq;
import com.retail.order.entity.request.SysAdminVerifyRequest;
import com.retail.order.enums.ExamineVerifyEnums;
import com.retail.order.enums.TiXianFlagEnums;
import com.retail.order.enums.VerifyTypeEnums;
import com.retail.order.mapper.AdminVerifyDetailOrderMapper;
import com.retail.order.mapper.RetailSettleOrderMapper;
import com.retail.order.mapper.SysAdminVerifyDetailMapper;
import com.retail.order.mapper.SysAdminVerifyMapper;
import com.retail.order.service.SysAdminVerifyService;
import com.retail.proxy.entity.vo.ProxyMechanismCategoryVo;
import com.retail.proxy.entity.vo.ProxyMechanismVo;
import com.retail.proxy.entity.vo.ProxyOrderAchieveVo;
import com.retail.proxy.mapper.ProxyMechanismCategoryMapper;
import com.retail.proxy.mapper.ProxyMechanismMapper;
import com.retail.proxy.mapper.ProxyOrderAchieveMapper;
import com.retail.shop.entity.vo.RetailShopVo;
import com.retail.shop.entity.vo.ShopCardLogVo;
import com.retail.shop.mapper.RetailAdminShopMapper;
import com.retail.shop.mapper.RetailShopMapper;
import com.retail.shop.mapper.ShopCardLogMapper;
import com.retail.system.entity.vo.AdminIncomePersonVo;
import com.retail.system.entity.vo.AdminUpgradeConfigVo;
import com.retail.system.entity.vo.AdminVo;
import com.retail.system.enums.AuditStatusEnums;
import com.retail.system.mapper.AdminMapper;
import com.retail.system.mapper.AdminUpgradeConfigMapper;
import com.retail.wxchat.entity.vo.RetailWxGetMoneyVo;
import com.retail.wxchat.mapper.RetailWxGetMoneyMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 用户核销单子 Service impl
 *
 * @author Administrator
 */
@Service
public class SysAdminVerifyServiceImpl implements SysAdminVerifyService {

    @Resource
    private AdminMapper adminMapper;
    @Resource
    private SysAdminVerifyMapper sysAdminVerifyMapper;

    @Resource
    private RetailShopMapper retailShopMapper;

    @Resource
    private RetailSettleOrderMapper retailSettleOrderMapper;

    @Resource
    private RetailAdminShopMapper retailAdminShopMapper;

    @Resource
    private SysAdminVerifyDetailMapper sysAdminVerifyDetailMapper;

    @Resource
    private RetailMsgService retailMsgService;

    @Resource
    private ProxyMechanismCategoryMapper proxyMechanismCategoryMapper;

    @Resource
    private ProxyMechanismMapper proxyMechanismMapper;

    @Resource
    private ShopCardLogMapper shopCardLogMapper;

    @Resource
    private RetailWxGetMoneyMapper retailWxGetMoneyMapper;

    @Resource
    private AdminVerifyDetailOrderMapper adminVerifyDetailOrderMapper;

    @Resource
    private ProxyOrderAchieveMapper proxyOrderAchieveMapper;

    @Resource
    private AdminUpgradeConfigMapper adminUpgradeConfigMapper;

    @Override
    public SysAdminVerifyVo getModel(Long id) {
        SysAdminVerifyVo vo = sysAdminVerifyMapper.getModel(id);
        vo.setExamineVerifyName(ExamineVerifyEnums.getStatusValues(vo.getExamineVerify()));
        vo.setTixianFlagName(TiXianFlagEnums.getStatusValues(vo.getTixianFlag()));
        if (ObjectUtil.isNotEmpty(vo) && ObjectUtil.isNotEmpty(vo.getAdminId())) {
//            AdminVo adminVo = adminMapper.getModel(vo.getAdminId());
//            if (ObjectUtil.isNotEmpty(adminVo)) {
//                vo.setAdminName(adminVo.getName());
//            }

//            Long adminLevel = adminVo.getAdminLevel();
//            ProxyMechanismCategoryVo pmCategory = proxyMechanismCategoryMapper.getModel(adminLevel);
//            if (ObjectUtil.isNotEmpty(pmCategory)) {
//                vo.setAdminLevelName(pmCategory.getCategoryName());
//            }

            verifyDetailList(id, vo);
        }
        return vo;
    }

    private void verifyDetailList(Long id, SysAdminVerifyVo vo) {
        List<SysAdminVerifyDetailVo> list = sysAdminVerifyDetailMapper.findModelByVerifyId(id);
        List<SysAdminVerifyDetailVo> shopCardLogs = new ArrayList<>();
        List<SysAdminVerifyDetailVo> personList = new ArrayList<>();
        List<SysAdminVerifyDetailVo> orderList = new ArrayList<>();
        List<SysAdminVerifyDetailVo> tuijianPersonOrderList = new ArrayList<>();
        List<SysAdminVerifyDetailVo> orderYearList = new ArrayList<>();
        list.forEach(l -> {
            if (ObjectUtil.notEqual(vo.getAdminLevel(), 1L)) {
                if (ObjectUtil.equal(l.getVerifyType(), VerifyTypeEnums.SHOP_VERIFY.getValue())) {
                    String objectId = l.getObjectId();
                    ShopCardLogVo shopCardLogVo = shopCardLogMapper.getModel(Long.parseLong(objectId));
                    RetailShopVo shopVo = retailShopMapper.getModel(shopCardLogVo.getShopId());
                    if (ObjectUtil.isNotEmpty(shopVo)) {
                        l.setObjectName(shopVo.getPoiName());

                        AdminVo gsAdminVo = retailAdminShopMapper.getModelByShopId(shopVo.getId());
                        if (ObjectUtil.isNotEmpty(gsAdminVo)) {
                            l.setAdminName(gsAdminVo.getName());
                        }
                    }

                    shopCardLogs.add(l);
                }
            }

            if (ObjectUtil.notEqual(vo.getAdminLevel(), 1L)) {
                if (ObjectUtil.equal(l.getVerifyType(), VerifyTypeEnums.PERSON_VERIFY.getValue())) {
                    AdminVo adminVo = adminMapper.getModel(Long.parseLong(l.getObjectId()));
                    if (ObjectUtil.isNotEmpty(adminVo)) {
                        l.setObjectName(adminVo.getName());
                    }

                    AdminVo parentAdminVo = adminMapper.getModel(l.getAdminId());
                    if (ObjectUtil.isNotEmpty(parentAdminVo)) {
                        l.setAdminName(parentAdminVo.getName());
                    }
                    personList.add(l);
                }
            }

            if (ObjectUtil.equal(l.getVerifyType(), VerifyTypeEnums.ORDER_MONTH_VERIFY.getValue())) {
                List<AdminVerifyDetailOrderVo> orderRequests = adminVerifyDetailOrderMapper.findVerifyOrderById(id);
                l.setOrderVerifyList(orderRequests);
                orderList.add(l);
            }

            if (ObjectUtil.notEqual(vo.getAdminLevel(), 1L)) {
                if (ObjectUtil.equal(l.getVerifyType(), VerifyTypeEnums.ORDER_YEAR_VERIFY.getValue())) {
                    List<SysAdminVerifyDetailVo> orderRequests = sysAdminVerifyDetailMapper.findModelByMonthOrders(vo.getAdminId(), vo.getVerifyYear());
                    for (SysAdminVerifyDetailVo orderRequest : orderRequests) {
                        Long verifyId = orderRequest.getVerifyId();
                        SysAdminVerifyVo sysAdminVerifyVo = sysAdminVerifyMapper.getModel(verifyId);
                        if (ObjectUtil.isNotEmpty(sysAdminVerifyVo)) {
                            orderRequest.setVerifyMonth(sysAdminVerifyVo.getVerifyMonth());
                        }
                    }
                    l.setSysAdminVerifyList(orderRequests);
                    orderYearList.add(l);
                }
            } else {
                if (ObjectUtil.equal(l.getVerifyType(), VerifyTypeEnums.ORDER_YEAR_VERIFY.getValue())) {
                    List<SysAdminVerifyDetailVo> orderRequests = sysAdminVerifyDetailMapper.findModelByMonthOrders(vo.getAdminId(), vo.getVerifyYear());
                    for (SysAdminVerifyDetailVo orderRequest : orderRequests) {
                        Long verifyId = orderRequest.getVerifyId();
                        SysAdminVerifyVo sysAdminVerifyVo = sysAdminVerifyMapper.getModel(verifyId);
                        if (ObjectUtil.isNotEmpty(sysAdminVerifyVo)) {
                            orderRequest.setVerifyMonth(sysAdminVerifyVo.getVerifyMonth());
                        }
                    }
                    l.setSysAdminVerifyList(orderRequests);
                    orderYearList.add(l);
                }
            }
            if (ObjectUtil.equal(vo.getAdminLevel(), 1L) && ObjectUtil.equal(l.getVerifyType(), VerifyTypeEnums.ORDER_TUIJIAN_VERIFY.getValue())) {
                tuijianPersonOrderList.add(l);
            }
        });
        vo.setShopCardLogList(shopCardLogs);
        vo.setPersonList(personList);
        vo.setTuijianPersonOrderList(tuijianPersonOrderList);
        if (ObjectUtil.isNotEmpty(orderList)) {
            vo.setOrder(orderList.get(0));
        }

        if (ObjectUtil.isNotEmpty(orderYearList)) {
            vo.setYearOrder(orderYearList.get(0));
        }
    }

    @Transactional
    @Override
    public Long save(SysAdminVerifyRequest sysAdminVerifyRequest) {
        sysAdminVerifyMapper.save(sysAdminVerifyRequest);
        return sysAdminVerifyRequest.getId();
    }

    @Transactional
    @Override
    public Long update(SysAdminVerifyRequest sysAdminVerifyRequest) {
        sysAdminVerifyMapper.update(sysAdminVerifyRequest);
        return sysAdminVerifyRequest.getId();
    }

    @Override
    public List<SysAdminVerifyVo> listPage(ParamReq<SysAdminVerifyRequest> params) {
        params.setStartIndex((params.getCurrent() - 1) * params.getSize());
        List<SysAdminVerifyVo> rets = sysAdminVerifyMapper.listPage(params);
        for (SysAdminVerifyVo ret : rets) {
            ret.setExamineVerifyName(ExamineVerifyEnums.getStatusValues(ret.getExamineVerify()));
            ret.setTixianFlagName(TiXianFlagEnums.getStatusValues(ret.getTixianFlag()));

//            if (ObjectUtil.isNotEmpty(ret) && ObjectUtil.isNotEmpty(ret.getAdminId())) {
//                AdminVo adminVo = adminMapper.getModel(ret.getAdminId());
//                if (ObjectUtil.isNotEmpty(adminVo)) {
//                    ret.setAdminName(adminVo.getName());
//                }
//
//                Long adminLevel = adminVo.getAdminLevel();
//                ProxyMechanismCategoryVo pmCategory = proxyMechanismCategoryMapper.getModel(adminLevel);
//                if (ObjectUtil.isNotEmpty(pmCategory)) {
//                    ret.setAdminLevelName(pmCategory.getCategoryName());
//                }
//            }

//            verifyDetailList(ret.getId(), ret);
        }

        return rets;
    }

    @Override
    public Integer countPage(ParamReq<SysAdminVerifyRequest> params) {
        return sysAdminVerifyMapper.countPage(params);
    }

    @Override
    public Integer updateDelFlagById(Long id, Integer delFlag) {
        return sysAdminVerifyMapper.updateDelFlagById(id, delFlag);
    }

    @Override
    public Result<Integer> verifyOrder(SysAdminVerifyRequest request) {
        SysAdminVerifyVo vo = sysAdminVerifyMapper.getModel(request.getId());
        Integer verifyCount = sysAdminVerifyMapper.verifyOrder(request.getId(), request.getExamineVerify(), request.getExamineVerifyRemark());
        if (ObjectUtil.equal(request.getExamineVerify(), ExamineVerifyEnums.SHEN_HE_TONGGUO.getValue()) || ObjectUtil.equal(request.getExamineVerify(), ExamineVerifyEnums.SHEN_HE_BUTONGGUO.getValue())) {
            insertVerifyMsg(vo, null);
        }
        return Result.success(verifyCount);
    }

    @Override
    public Result<Integer> tixianOrders(SysAdminVerifyRequest request) {
        SysAdminVerifyVo vo = sysAdminVerifyMapper.getModel(request.getId());
        Integer verifyCount = sysAdminVerifyMapper.tixianOrders(request.getId(), request.getExamineVerify(), request.getTixianRemark());
        if (ObjectUtil.equal(request.getTixianFlag(), TiXianFlagEnums.YI_TI_XIAN.getValue()) || ObjectUtil.equal(request.getTixianFlag(), TiXianFlagEnums.TI_XIAN_SHIBAI.getValue())) {
            insertVerifyMsg(vo, null);
        }
        return Result.success(verifyCount);
    }

    @Override
    public SysAdminVerifyStasticResVo passVerifyStasticById(Long adminId) {
        List<SysAdminVerifyVo> list = passVerifyStasticList(adminId);

//        SysAdminVerifyStasticResVo res = SysAdminVerifyStasticResVo.builder().verifyCount(list.size()).orderCount(0).ownerOrderCount(0).totalPrice(new BigDecimal(0)).ownerOrderPrice(new BigDecimal(0)).totalVerifPrice(new BigDecimal(0)).totalOwnerVerifPrice(new BigDecimal(0)).wechatPrice(new BigDecimal(0)).build();
//        for (SysAdminVerifyVo l : list) {
//            res.setOrderCount(res.getOrderCount() + l.getOrderCount());
//            res.setOwnerOrderCount(res.getOwnerOrderCount() + l.getOwnerOrderCount());
//            res.setTotalPrice(res.getTotalPrice().add(l.getTotalPrice()));
//            res.setOwnerOrderPrice(res.getOwnerOrderPrice().add(l.getOwnerOrderPrice()));
//
//            res.setTotalVerifPrice(res.getTotalVerifPrice().add(l.getTotalVerifPrice()));
//            res.setTotalOwnerVerifPrice(res.getTotalOwnerVerifPrice().add(l.getTotalOwnerVerifPrice()));
//            res.setWechatPrice(res.getWechatPrice().add(l.getWechatPrice()));
//        }
        SysAdminVerifyStasticResVo sa = SysAdminVerifyStasticResVo.builder().build();
        return sa;
    }

    @Override
    public List<SysAdminVerifyVo> passVerifyStasticList(Long adminId) {
        List<SysAdminVerifyVo> ret = sysAdminVerifyMapper.passVerifyStasticList(adminId);
        ret.forEach(r -> {
//            List<SysAdminVerifyDetailVo> verifyOrders = sysAdminVerifyDetailMapper.findModelByVerifyId(r.getId());
//            r.setOrderDetails(verifyOrders);
        });

        return ret;
    }

    @Override
    public List<SysAdminVerifyVo> adminVerifyListStatus(Long adminId, Integer examineVerify) {
        return sysAdminVerifyMapper.adminVerifyListStatus(adminId, examineVerify);
    }

    /**
     * 核销(用户核销)
     *
     * @param request
     * @return
     */
    @Override
    public Integer operUserMonthVerify(SysAdminVerifyRequest request) {
        RetailWxGetMoneyVo wxGetMoney = retailWxGetMoneyMapper.getUseModel();
        List<AdminVo> verifyAdmins = adminMapper.findAllAdminsByAuditStatus(AuditStatusEnums.VERIFY_SUCCESS.getValue());
        verifyAdmins.forEach(verifyAdmin -> {
            SysAdminVerifyVo sysAVerifyVo = sysAdminVerifyMapper.findAdminVerifyByAdminIDAndVerifyMonth(verifyAdmin.getId(), request.getVerifyMonth());
            if (ObjectUtil.isEmpty(sysAVerifyVo) || ObjectUtil.notEqual(sysAVerifyVo.getTixianFlag(), 1)) {
                deleteVerifyAndVerifyDetail(request, verifyAdmin);
                SysAdminVerifyRequest adminVerifyRequest = saveAdminVerifyRequest(request, wxGetMoney, verifyAdmin);
                Long adminLevel = verifyAdmin.getAdminLevel();
                // 代理业绩
                if (adminLevel > 1) {
                    ProxyMechanismVo proxyMechanismVo = proxyMechanismMapper.getModelByProxyLevel(adminLevel);
                    // 商户订单推广
                    calculateShopCardLog(request, verifyAdmin, adminVerifyRequest, proxyMechanismVo);
                    // 代理等级计算
                    calculatePersonLevel(verifyAdmin, adminVerifyRequest, adminLevel);
                    // 月度奖励
                    calculateOrderMonth(verifyAdmin, adminVerifyRequest, adminLevel);
                } else {
                    Long retUpgradeLevel = getCurentUpgradeLevel(request, verifyAdmin, 1);
                    // retUpgradeLevel 当月订单
                    if (ObjectUtil.isNotEmpty(retUpgradeLevel)) {
                        AdminUpgradeConfigVo adminUpgradeConfigVo = adminUpgradeConfigMapper.getModel(retUpgradeLevel);
                        calculateYwyOrderMonth(verifyAdmin, adminVerifyRequest, adminUpgradeConfigVo, request.getVerifyMonth());
                    }
                    calculateTuijianYwyMonth(verifyAdmin, adminVerifyRequest, request.getVerifyMonth());
                }
                sysAdminVerifyMapper.updatePriceByVerifyId(adminVerifyRequest.getId());

                try {
                    SysAdminVerifyVo sysAdminVerifyVo = sysAdminVerifyMapper.getModel(adminVerifyRequest.getId());
                    insertVerifyMsg(sysAdminVerifyVo, 1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        return 1;
    }

    /**
     * 得到当前等级
     *
     * @param request
     * @param verifyAdmin
     * @param upgradeLevelType 1 月度 2-年度
     * @return
     */
    private Long getCurentUpgradeLevel(SysAdminVerifyRequest request, AdminVo verifyAdmin, Integer upgradeLevelType) {
        // 计算当月的数据
        Long upgradeLevel = verifyAdmin.getUpgradeLevel();
        Long preUpgradeLevel = verifyAdmin.getUpgradePreLevel();
        Long retUpgradeLevel = upgradeLevel;
        if (ObjectUtil.equal(upgradeLevelType, 1L)) {
            String upgradeTime = verifyAdmin.getUpgradeTime();
            if (ObjectUtil.isNotEmpty(upgradeTime)) {
                Date upgradeTimeD = DateUtil.parse(upgradeTime, "yyyy-MM-dd");
                Date verifyTime = DateUtil.parse(request.getVerifyMonth(), "yyyy-MM");

                String yM = DateUtil.format(upgradeTimeD, "yyyy-MM");
                String cYm = DateUtil.format(verifyTime, "yyyy-MM");
                if (ObjectUtil.equal(yM, cYm)) {
                    retUpgradeLevel = preUpgradeLevel;
                } else {
                    Date vtd = DateUtil.parse(upgradeTime, "yyyy-MM");
                    if (verifyTime.getTime() < vtd.getTime()) {
                        retUpgradeLevel = preUpgradeLevel;
                    }
                }
            }
        }
        return retUpgradeLevel;
    }

    /**
     * 核销(用户核销-年份)
     *
     * @param request
     * @return
     */
    @Override
    public Integer operUserYearVerify(SysAdminVerifyRequest request) {
        RetailWxGetMoneyVo wxGetMoney = retailWxGetMoneyMapper.getUseModel();
        List<AdminVo> verifyAdmins = adminMapper.findAllAdminsByAuditStatus(AuditStatusEnums.VERIFY_SUCCESS.getValue());
        verifyAdmins.forEach(verifyAdmin -> {
            SysAdminVerifyVo sysAVerifyVo = sysAdminVerifyMapper.findAdminVerifyByAdminIDAndVerifyYear(verifyAdmin.getId(), request.getVerifyMonth());
            if (ObjectUtil.isEmpty(sysAVerifyVo) || ObjectUtil.notEqual(sysAVerifyVo.getTixianFlag(), 1)) {
                Long adminLevel = verifyAdmin.getAdminLevel();
                deleteVerifyAndVerifyYearDetail(request, verifyAdmin);
                SysAdminVerifyRequest adminVerifyRequest = saveAdminVerifyRequest(request, wxGetMoney, verifyAdmin);
                if (adminLevel > 1) {
                    // 年度奖励
                    calculateOrderYear(verifyAdmin, request.getVerifyYear(), adminVerifyRequest, adminLevel);
                } else {
                    // 年度费用结算。
                    Long retUpgradeLevel = getCurentUpgradeLevel(request, verifyAdmin, 2);
                    if (ObjectUtil.isNotEmpty(retUpgradeLevel)) {
                        AdminUpgradeConfigVo adminUpgradeConfigVo = adminUpgradeConfigMapper.getModel(retUpgradeLevel);
                        // 年度奖励
                        calculateOrderYwyYear(verifyAdmin, request.getVerifyYear(), adminVerifyRequest, adminUpgradeConfigVo);
                    }
                }
                sysAdminVerifyMapper.updatePriceByVerifyId(adminVerifyRequest.getId());

                try {
                    SysAdminVerifyVo sysAdminVerifyVo = sysAdminVerifyMapper.getModel(adminVerifyRequest.getId());
                    insertVerifyMsg(sysAdminVerifyVo, 2);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        return 1;
    }

    /**
     * 订单月度奖励
     *
     * @param verifyAdmin        团队长
     * @param adminVerifyRequest 佣金编号
     */
    private void calculateTuijianYwyMonth(AdminVo verifyAdmin, SysAdminVerifyRequest adminVerifyRequest, String verifyMonth) {
        List<AdminVo> childs = adminMapper.getChildByParentId(verifyAdmin.getId());
        // a 用户的子用户
        childs.forEach(child -> {
            List<RetailSettleOrderVo> adminOrders = retailSettleOrderMapper.findtoBeanVerifyOrderByYwyAdminId(child.getId(), verifyMonth + "-01");
            BigDecimal totalPrice = new BigDecimal(0);
            Long retUpgradeLevel = getCurentUpgradeLevel(adminVerifyRequest, child, 1);
            AdminUpgradeConfigVo adminUpgradeConfigVo = adminUpgradeConfigMapper.getModel(retUpgradeLevel);

            for (RetailSettleOrderVo order : adminOrders) {
                AdminVerifyDetailOrderRequest vdoRequest = new AdminVerifyDetailOrderRequest();
                vdoRequest.setVerifyId(adminVerifyRequest.getId());
                vdoRequest.setVerifyDetailId(null);
                vdoRequest.setAdminId(verifyAdmin.getId());
                vdoRequest.setObjectId(order.getId());
                vdoRequest.setOrderId(order.getOrderId());
                vdoRequest.setTotalPrice(order.getReceiptAmount());
                vdoRequest.setTotalVerifyPrice(adminUpgradeConfigVo.getOrderPrice());
                vdoRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
                vdoRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
                vdoRequest.setDelFlag(DelFlagEnum.NO.getValue());
                vdoRequest.setRemark("");
                adminVerifyDetailOrderMapper.save(vdoRequest);
                totalPrice = totalPrice.add(adminUpgradeConfigVo.getOrderPrice());
            }
            SysAdminVerifyDetailRequest detailRequest = new SysAdminVerifyDetailRequest();
            detailRequest.setVerifyId(adminVerifyRequest.getId());
            detailRequest.setAdminId(child.getId());
            detailRequest.setObjectId(child.getId() + "");
            detailRequest.setVerifyType(VerifyTypeEnums.ORDER_TUIJIAN_VERIFY.getValue());

            // 核销情况
            if (new Date().getYear() - child.getCreateTime().getYear() == 0) {
                detailRequest.setTotalVerifyPrice(totalPrice.multiply(new BigDecimal("5")).divide(new BigDecimal(100)));
                detailRequest.setRemark(child.getName() + ":" + totalPrice + "：团购券获利的5%佣金");
            } else {
                if (new Date().getYear() - child.getCreateTime().getYear() == 1) {
                    detailRequest.setTotalVerifyPrice(totalPrice.multiply(new BigDecimal("2")).divide(new BigDecimal(100)));
                    detailRequest.setRemark(child.getName() + ":" + totalPrice + "：团购券获利的2%佣金");
                } else {
                    detailRequest.setTotalVerifyPrice(new BigDecimal("0"));
                    detailRequest.setRemark("：团购券获利的0元佣金");
                }
            }
            detailRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            detailRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
            detailRequest.setDelFlag(DelFlagEnum.NO.getValue());
            detailRequest.setCreateUser(1L);
            sysAdminVerifyDetailMapper.save(detailRequest);
            adminVerifyDetailOrderMapper.updateVerifyDetailIdByVerifyId(adminVerifyRequest.getId(), detailRequest.getId());
        });
    }

    private BigDecimal calculateTuijianYwyMonth0(AdminVo verifyAdmin, String verifyMonth) {
        List<AdminVo> childs = adminMapper.getChildByParentId(verifyAdmin.getId());
        BigDecimal retTotalPrice = new BigDecimal(0);
        // a 用户的子用户
        for (AdminVo child : childs) {
            List<RetailSettleOrderVo> adminOrders = retailSettleOrderMapper.findtoBeanVerifyOrderByYwyAdminId(child.getId(), verifyMonth + "-01");
            BigDecimal totalPrice = new BigDecimal(0);
            AdminUpgradeConfigVo adminUpgradeConfigVo = adminUpgradeConfigMapper.getModel(verifyAdmin.getUpgradeLevel());

            totalPrice = totalPrice.add(new BigDecimal(adminOrders.size() + "").multiply(adminUpgradeConfigVo.getOrderPrice()));
            // 核销情况
            if (new Date().getYear() - child.getCreateTime().getYear() == 0) {
                retTotalPrice = retTotalPrice.add(totalPrice.multiply(new BigDecimal("5")).divide(new BigDecimal(100)));
            } else {
                if (new Date().getYear() - child.getCreateTime().getYear() == 1) {
                    retTotalPrice = retTotalPrice.add(totalPrice.multiply(new BigDecimal("2")).divide(new BigDecimal(100)));
                }
            }
        }
        return retTotalPrice;
    }

    private BigDecimal calculateTuijianYwyMonth1(AdminVo verifyAdmin, String verifyMonth) {
        List<AdminVo> childs = adminMapper.getChildByParentId(verifyAdmin.getId());
        BigDecimal retTotalPrice = new BigDecimal(0);
        AdminUpgradeConfigVo adminUpgradeConfigVo = adminUpgradeConfigMapper.getModel(verifyAdmin.getUpgradeLevel());
        // a 用户的子用户
        for (AdminVo child : childs) {
            List<RetailSettleOrderVo> adminOrders = retailSettleOrderMapper.findtoBeanVerifyOrderByYwyAdminIdDay(child.getId(), verifyMonth);
            BigDecimal totalPrice = new BigDecimal(0);

            totalPrice = totalPrice.add(new BigDecimal(adminOrders.size() + "").multiply(adminUpgradeConfigVo.getOrderPrice()));
            // 核销情况
            if (new Date().getYear() - child.getCreateTime().getYear() == 0) {
                retTotalPrice = retTotalPrice.add(totalPrice.multiply(new BigDecimal("5")).divide(new BigDecimal(100)));
            } else {
                if (new Date().getYear() - child.getCreateTime().getYear() == 1) {
                    retTotalPrice = retTotalPrice.add(totalPrice.multiply(new BigDecimal("2")).divide(new BigDecimal(100)));
                }
            }
        }
        return retTotalPrice;
    }

    /**
     * 订单月度奖励
     *
     * @param verifyAdmin
     * @param adminVerifyRequest
     */
    private void calculateYwyOrderMonth(AdminVo verifyAdmin, SysAdminVerifyRequest adminVerifyRequest, AdminUpgradeConfigVo adminUpgradeConfigVo, String verifyMonth) {
        List<RetailSettleOrderVo> adminOrders = retailSettleOrderMapper.findtoBeanVerifyOrderByYwyAdminId(verifyAdmin.getId(), verifyMonth + "-01");
        BigDecimal totalPrice = new BigDecimal(0);
        for (RetailSettleOrderVo order : adminOrders) {
            AdminVerifyDetailOrderRequest vdoRequest = new AdminVerifyDetailOrderRequest();
            vdoRequest.setVerifyId(adminVerifyRequest.getId());
            vdoRequest.setVerifyDetailId(null);
            vdoRequest.setAdminId(verifyAdmin.getId());
            vdoRequest.setObjectId(order.getId());
            vdoRequest.setOrderId(order.getOrderId());
            vdoRequest.setTotalPrice(order.getReceiptAmount());
            vdoRequest.setTotalVerifyPrice(null);
            vdoRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            vdoRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
            vdoRequest.setDelFlag(DelFlagEnum.NO.getValue());
            vdoRequest.setRemark("");
            adminVerifyDetailOrderMapper.save(vdoRequest);
            totalPrice = totalPrice.add(order.getReceiptAmount());
        }

        SysAdminVerifyDetailRequest detailRequest = new SysAdminVerifyDetailRequest();
        detailRequest.setVerifyId(adminVerifyRequest.getId());
        detailRequest.setAdminId(verifyAdmin.getId());
        detailRequest.setObjectId(verifyAdmin.getId() + "");
        detailRequest.setVerifyType(VerifyTypeEnums.ORDER_MONTH_VERIFY.getValue());
        detailRequest.setTotalPrice(totalPrice);

        // 核销情况
        detailRequest.setTotalVerifyPrice(adminUpgradeConfigVo.getOrderPrice().multiply(new BigDecimal(adminOrders.size() + "")));
        detailRequest.setRemark("订单数量：" + adminOrders.size());

        detailRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        detailRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
        detailRequest.setDelFlag(DelFlagEnum.NO.getValue());
        detailRequest.setCreateUser(1L);
        sysAdminVerifyDetailMapper.save(detailRequest);

        adminVerifyDetailOrderMapper.updateVerifyDetailIdByVerifyId(adminVerifyRequest.getId(), detailRequest.getId());
    }

    /**
     * 订单月度奖励
     *
     * @param verifyAdmin
     */
    private BigDecimal calculateYwyOrderMonth0(AdminVo verifyAdmin, AdminUpgradeConfigVo adminUpgradeConfigVo, String verifyMonth) {
        List<RetailSettleOrderVo> adminOrders = retailSettleOrderMapper.findtoBeanVerifyOrderByYwyAdminId(verifyAdmin.getId(), verifyMonth + "-01");
        // 核销情况
        return adminUpgradeConfigVo.getOrderPrice().multiply(new BigDecimal(adminOrders.size() + ""));
    }

    private BigDecimal calculateYwyOrderMonth1(AdminVo verifyAdmin, AdminUpgradeConfigVo adminUpgradeConfigVo, String verifyMonth) {
        List<RetailSettleOrderVo> adminOrders = retailSettleOrderMapper.findtoBeanVerifyOrderByYwyAdminIdDay(verifyAdmin.getId(), verifyMonth);
        // 核销情况
        return adminUpgradeConfigVo.getOrderPrice().multiply(new BigDecimal(adminOrders.size() + ""));
    }

    /**
     * 订单月度奖励
     *
     * @param verifyAdmin
     * @param adminVerifyRequest
     * @param adminLevel
     */
    private void calculateOrderMonth(AdminVo verifyAdmin, SysAdminVerifyRequest adminVerifyRequest, Long adminLevel) {
        List<RetailSettleOrderVo> adminOrders = retailSettleOrderMapper.findtoBeanVerifyOrderByAdminId(verifyAdmin.getId(), adminVerifyRequest.getVerifyMonth() + "-01");
        BigDecimal totalPrice = new BigDecimal(0);
        for (RetailSettleOrderVo order : adminOrders) {
            AdminVerifyDetailOrderRequest vdoRequest = new AdminVerifyDetailOrderRequest();
            vdoRequest.setVerifyId(adminVerifyRequest.getId());
            vdoRequest.setVerifyDetailId(null);
            vdoRequest.setAdminId(verifyAdmin.getId());
            vdoRequest.setObjectId(order.getId());
            vdoRequest.setOrderId(order.getOrderId());
            vdoRequest.setTotalPrice(order.getReceiptAmount());
            vdoRequest.setTotalVerifyPrice(null);
            vdoRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            vdoRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
            vdoRequest.setDelFlag(DelFlagEnum.NO.getValue());
            vdoRequest.setRemark("");
            adminVerifyDetailOrderMapper.save(vdoRequest);
            totalPrice = totalPrice.add(order.getReceiptAmount());
        }

        SysAdminVerifyDetailRequest detailRequest = new SysAdminVerifyDetailRequest();
        detailRequest.setVerifyId(adminVerifyRequest.getId());
        detailRequest.setAdminId(verifyAdmin.getId());
        detailRequest.setObjectId(verifyAdmin.getId() + "");
        detailRequest.setVerifyType(VerifyTypeEnums.ORDER_MONTH_VERIFY.getValue());
        detailRequest.setTotalPrice(totalPrice);

        // 核销情况
        Date vMonth = DateUtil.parse(adminVerifyRequest.getVerifyMonth(), "yyyy-MM");
        String mm = DateUtil.format(vMonth, "MM");
        ProxyOrderAchieveVo proxyOrderAchieveVo = proxyOrderAchieveMapper.findAchieveByCategoryIdAndAchieveTypeAndMonth(adminLevel, 1, Integer.parseInt(mm));
        if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo)) {
            if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo.getAcheive1Start())) {
                if (totalPrice.subtract(proxyOrderAchieveVo.getAcheive1Start()).doubleValue() >= 0) {
                    detailRequest.setTotalVerifyPrice(new BigDecimal(proxyOrderAchieveVo.getAcheive1Price()));
                    detailRequest.setRemark(proxyOrderAchieveVo.getAcheive1Desc());
                }
            }

            if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo.getAcheive2Start())) {
                if (totalPrice.subtract(proxyOrderAchieveVo.getAcheive2Start()).doubleValue() >= 0) {
                    detailRequest.setTotalVerifyPrice(new BigDecimal(proxyOrderAchieveVo.getAcheive2Price()));
                    detailRequest.setRemark(proxyOrderAchieveVo.getAcheive2Desc());
                }
            }
        }

        detailRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        detailRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
        detailRequest.setDelFlag(DelFlagEnum.NO.getValue());
        detailRequest.setCreateUser(1L);
        sysAdminVerifyDetailMapper.save(detailRequest);

        adminVerifyDetailOrderMapper.updateVerifyDetailIdByVerifyId(adminVerifyRequest.getId(), detailRequest.getId());
    }

    private BigDecimal calculateOrderMonth0(String verifyMonth, AdminVo verifyAdmin, Long adminLevel) {
        List<RetailSettleOrderVo> adminOrders = retailSettleOrderMapper.findtoBeanVerifyOrderByAdminId(verifyAdmin.getId(), verifyMonth + "-01");
        BigDecimal totalPrice = new BigDecimal(0);
        BigDecimal retTotalPrice = new BigDecimal(0);

        for (RetailSettleOrderVo order : adminOrders) {
            totalPrice = totalPrice.add(order.getReceiptAmount());
        }

        // 核销情况
        String mm = DateUtil.format(new Date(), "MM");
        ProxyOrderAchieveVo proxyOrderAchieveVo = proxyOrderAchieveMapper.findAchieveByCategoryIdAndAchieveTypeAndMonth(adminLevel, 1, Integer.parseInt(mm));
        if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo)) {
            if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo.getAcheive1Start())) {
                if (totalPrice.subtract(proxyOrderAchieveVo.getAcheive1Start()).doubleValue() >= 0) {
                    retTotalPrice = retTotalPrice.add(new BigDecimal(proxyOrderAchieveVo.getAcheive1Price()));
                }
            }

            if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo.getAcheive2Start())) {
                if (totalPrice.subtract(proxyOrderAchieveVo.getAcheive2Start()).doubleValue() >= 0) {
                    retTotalPrice = retTotalPrice.add((new BigDecimal(proxyOrderAchieveVo.getAcheive2Price())));
                }
            }
        }

        return retTotalPrice;
    }

    private BigDecimal calculateOrderMonth1(String verifyMonth, AdminVo verifyAdmin, Long adminLevel) {
        List<RetailSettleOrderVo> adminOrders = retailSettleOrderMapper.findtoBeanVerifyOrderByAdminIdDay(verifyAdmin.getId(), verifyMonth);
        BigDecimal totalPrice = new BigDecimal(0);
        BigDecimal retTotalPrice = new BigDecimal(0);

        for (RetailSettleOrderVo order : adminOrders) {
            totalPrice = totalPrice.add(order.getReceiptAmount());
        }

        // 核销情况
        String mm = DateUtil.format(new Date(), "MM");
        ProxyOrderAchieveVo proxyOrderAchieveVo = proxyOrderAchieveMapper.findAchieveByCategoryIdAndAchieveTypeAndMonth(adminLevel, 1, Integer.parseInt(mm));
        if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo)) {
            if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo.getAcheive1Start())) {
                if (totalPrice.subtract(proxyOrderAchieveVo.getAcheive1Start()).doubleValue() >= 0) {
                    retTotalPrice = retTotalPrice.add(new BigDecimal(proxyOrderAchieveVo.getAcheive1Price()));
                }
            }

            if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo.getAcheive2Start())) {
                if (totalPrice.subtract(proxyOrderAchieveVo.getAcheive2Start()).doubleValue() >= 0) {
                    retTotalPrice = retTotalPrice.add((new BigDecimal(proxyOrderAchieveVo.getAcheive2Price())));
                }
            }
        }

        return retTotalPrice;
    }

    /**
     * 订单月度奖励
     *
     * @param verifyAdmin
     * @param adminVerifyRequest
     * @param adminLevel
     */
    private void calculateOrderYear(AdminVo verifyAdmin, String verifyYear, SysAdminVerifyRequest adminVerifyRequest, Long adminLevel) {
        List<SysAdminVerifyDetailVo> adminOrders = sysAdminVerifyDetailMapper.findModelByMonthOrders(verifyAdmin.getId(), verifyYear);
        BigDecimal totalPrice = new BigDecimal(0);
        for (SysAdminVerifyDetailVo verifyDetailVo : adminOrders) {
            totalPrice = totalPrice.add(verifyDetailVo.getTotalPrice());
        }

        SysAdminVerifyDetailRequest detailRequest = new SysAdminVerifyDetailRequest();
        detailRequest.setVerifyId(adminVerifyRequest.getId());
        detailRequest.setAdminId(verifyAdmin.getId());
        detailRequest.setObjectId(verifyAdmin.getId() + "");
        detailRequest.setVerifyType(VerifyTypeEnums.ORDER_YEAR_VERIFY.getValue());
        detailRequest.setTotalPrice(totalPrice);

        // 核销情况
        String mm = DateUtil.format(new Date(), "MM");
        ProxyOrderAchieveVo proxyOrderAchieveVo = proxyOrderAchieveMapper.findAchieveByCategoryIdAndAchieveTypeAndYear(adminLevel, 0);
        if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo)) {
            if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo.getAcheive1Start()) && totalPrice.subtract(proxyOrderAchieveVo.getAcheive1Start()).doubleValue() > 0) {

                if (ObjectUtil.contains(proxyOrderAchieveVo.getAcheive1Price(), "%")) {
                    detailRequest.setTotalVerifyPrice(totalPrice.multiply(new BigDecimal(proxyOrderAchieveVo.getAcheive1Price().replace("%", ""))).divide(new BigDecimal(100)));
                } else {
                    detailRequest.setTotalVerifyPrice(new BigDecimal(proxyOrderAchieveVo.getAcheive1Price()));
                }
                detailRequest.setRemark(proxyOrderAchieveVo.getAcheive1Desc());
            }

            if (ObjectUtil.isNotEmpty(proxyOrderAchieveVo.getAcheive2Start()) && totalPrice.subtract(proxyOrderAchieveVo.getAcheive2Start()).doubleValue() > 0) {
                if (ObjectUtil.contains(proxyOrderAchieveVo.getAcheive2Price(), "%")) {
                    detailRequest.setTotalVerifyPrice(totalPrice.multiply(new BigDecimal(proxyOrderAchieveVo.getAcheive2Price().replace("%", ""))).divide(new BigDecimal(100)));
                } else {
                    detailRequest.setTotalVerifyPrice(new BigDecimal(proxyOrderAchieveVo.getAcheive2Price()));
                }
                detailRequest.setRemark(proxyOrderAchieveVo.getAcheive2Desc());
            }
        }

        detailRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        detailRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
        detailRequest.setDelFlag(DelFlagEnum.NO.getValue());
        detailRequest.setCreateUser(1L);
        sysAdminVerifyDetailMapper.save(detailRequest);

        adminVerifyDetailOrderMapper.updateVerifyDetailIdByVerifyId(adminVerifyRequest.getId(), detailRequest.getId());
    }

    /**
     * 商户年度核销奖励
     *
     * @param verifyAdmin
     * @param adminVerifyRequest
     * @param adminUpgradeConfigVo 晋升比率
     */
    private void calculateOrderYwyYear(AdminVo verifyAdmin, String verifyYear, SysAdminVerifyRequest adminVerifyRequest, AdminUpgradeConfigVo adminUpgradeConfigVo) {
        List<ShopCardLogVo> cardLogVos = shopCardLogMapper.findOwnerShopAndYear(verifyAdmin.getId(), verifyYear);
        BigDecimal totalPrice = new BigDecimal(0);
        for (ShopCardLogVo verifyDetailVo : cardLogVos) {
            totalPrice = totalPrice.add(verifyDetailVo.getCardPrice());
        }

        SysAdminVerifyDetailRequest detailRequest = new SysAdminVerifyDetailRequest();
        detailRequest.setVerifyId(adminVerifyRequest.getId());
        detailRequest.setAdminId(verifyAdmin.getId());
        detailRequest.setObjectId(verifyAdmin.getId() + "");
        detailRequest.setVerifyType(VerifyTypeEnums.ORDER_YEAR_VERIFY.getValue());
        detailRequest.setTotalPrice(totalPrice);

        // 核销情况
        detailRequest.setTotalVerifyPrice(totalPrice.multiply(adminUpgradeConfigVo.getPitchPricePer()).divide(new BigDecimal(100)));
        detailRequest.setRemark("推销商户佣金比：" + adminUpgradeConfigVo.getPitchPricePer() + "%");
        detailRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        detailRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
        detailRequest.setDelFlag(DelFlagEnum.NO.getValue());
        detailRequest.setCreateUser(1L);
        sysAdminVerifyDetailMapper.save(detailRequest);
    }

    private void calculatePersonLevel(AdminVo verifyAdmin, SysAdminVerifyRequest adminVerifyRequest, Long adminLevel) {
        // 商户推广
        List<AdminVo> childAdmins = adminMapper.findAllAdminsByParentIdAndAuditStatus(verifyAdmin.getId(), AuditStatusEnums.VERIFY_SUCCESS.getValue());
        for (AdminVo admin : childAdmins) {
            SysAdminVerifyDetailVo verifyDetailVo = sysAdminVerifyDetailMapper.getUseAdminVerifyDetailByObjectIdAndVerifyType(verifyAdmin.getId(), admin.getId(), VerifyTypeEnums.PERSON_VERIFY.getValue());
            if (ObjectUtil.isEmpty(verifyDetailVo)) {
                SysAdminVerifyDetailRequest detailRequest = new SysAdminVerifyDetailRequest();
                detailRequest.setVerifyId(adminVerifyRequest.getId());
                detailRequest.setAdminId(verifyAdmin.getId());
                detailRequest.setObjectId(admin.getId() + "");
                detailRequest.setVerifyType(VerifyTypeEnums.PERSON_VERIFY.getValue());
                // 普通代理
                if (ObjectUtil.equal(adminLevel, 1L)) {
                    detailRequest.setTotalPrice(new BigDecimal(200000));
                    if (ObjectUtil.equal(admin.getAdminLevel(), 1L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(0));
                        detailRequest.setRemark("奖励0元");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 2L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(20000));
                        detailRequest.setRemark("奖励2万");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 3L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(30000));
                        detailRequest.setRemark("奖励3万");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 4L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(80000));
                        detailRequest.setRemark("奖励8万");
                    }
                    // 标准代理
                } else if (ObjectUtil.equal(adminLevel, 2L)) {
                    detailRequest.setTotalPrice(new BigDecimal(200000));
                    if (ObjectUtil.equal(admin.getAdminLevel(), 1L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(0));
                        detailRequest.setRemark("奖励0元");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 2L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(20000));
                        detailRequest.setRemark("奖励2万");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 3L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(30000));
                        detailRequest.setRemark("奖励3万");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 4L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(80000));
                        detailRequest.setRemark("奖励8万");
                    }
                    // 高级代理
                } else if (ObjectUtil.equal(adminLevel, 3L)) {
                    detailRequest.setTotalPrice(new BigDecimal(350000));
                    if (ObjectUtil.equal(admin.getAdminLevel(), 1L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(0));
                        detailRequest.setRemark("奖励0元");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 2L)) {
                        List<AdminVo> child2Admins = adminMapper.findAllAdminsByParentIdAndAuditStatus(admin.getId(), AuditStatusEnums.VERIFY_SUCCESS.getValue());
                        Integer count = 0;
                        for (AdminVo child2 : child2Admins) {
                            SysAdminVerifyDetailVo verifyDetail2Vo = sysAdminVerifyDetailMapper.getUseAdminVerifyDetailByObjectIdAndVerifyType(verifyAdmin.getId(), admin.getId(), VerifyTypeEnums.PERSON_VERIFY.getValue());
                            if ((ObjectUtil.isEmpty(verifyDetail2Vo) || ObjectUtil.equal(verifyDetail2Vo.getVerifyId(), adminVerifyRequest.getId())) && ObjectUtil.equal(child2.getAdminLevel(), 2L)) {
                                ++count;
                            }
                        }
                        BigDecimal total = new BigDecimal(20000).add(new BigDecimal(count * 20000 * 10 / 100));
                        detailRequest.setTotalVerifyPrice(total);
                        detailRequest.setRemark("奖励2万+标准代理的10%");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 3L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(30000));
                        detailRequest.setRemark("奖励3万");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 4L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(80000));
                        detailRequest.setRemark("奖励8万");
                    }
                    // 至尊代理
                } else if (ObjectUtil.equal(adminLevel, 4L)) {
                    detailRequest.setTotalPrice(new BigDecimal(700000));
                    if (ObjectUtil.equal(admin.getAdminLevel(), 1L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(0));
                        detailRequest.setRemark("奖励0元");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 2L)) {
                        List<AdminVo> child2Admins = adminMapper.findAllAdminsByParentIdAndAuditStatus(admin.getId(), AuditStatusEnums.VERIFY_SUCCESS.getValue());
                        Integer count = 0;
                        for (AdminVo child2 : child2Admins) {
                            SysAdminVerifyDetailVo verifyDetail2Vo = sysAdminVerifyDetailMapper.getUseAdminVerifyDetailByObjectIdAndVerifyType(verifyAdmin.getId(), admin.getId(), VerifyTypeEnums.PERSON_VERIFY.getValue());
                            if ((ObjectUtil.isEmpty(verifyDetail2Vo) || ObjectUtil.equal(verifyDetail2Vo.getVerifyId(), adminVerifyRequest.getId())) && ObjectUtil.equal(child2.getAdminLevel(), 2L)) {
                                ++count;
                            }
                        }
                        BigDecimal total = new BigDecimal(20000).add(new BigDecimal(count * 20000 * 10 / 100));
                        detailRequest.setTotalVerifyPrice(total);
                        detailRequest.setRemark("奖励2万+标准代理的10%");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 3L)) {
                        List<AdminVo> child2Admins = adminMapper.findAllAdminsByParentIdAndAuditStatus(admin.getId(), AuditStatusEnums.VERIFY_SUCCESS.getValue());
                        Integer bzcount = 0;
                        Integer gjcount = 0;
                        for (AdminVo child2 : child2Admins) {
                            SysAdminVerifyDetailVo verifyDetail2Vo = sysAdminVerifyDetailMapper.getUseAdminVerifyDetailByObjectIdAndVerifyType(verifyAdmin.getId(), admin.getId(), VerifyTypeEnums.PERSON_VERIFY.getValue());
                            if ((ObjectUtil.isEmpty(verifyDetail2Vo) || ObjectUtil.equal(verifyDetail2Vo.getVerifyId(), adminVerifyRequest.getId())) && ObjectUtil.equal(child2.getAdminLevel(), 2L)) {
                                ++bzcount;
                            }
                            if ((ObjectUtil.isEmpty(verifyDetail2Vo) || ObjectUtil.equal(verifyDetail2Vo.getVerifyId(), adminVerifyRequest.getId())) && ObjectUtil.equal(child2.getAdminLevel(), 3L)) {
                                ++gjcount;
                            }
                        }
                        BigDecimal total = new BigDecimal(30000).add(new BigDecimal(bzcount * 20000 * 5 / 100 + gjcount * 30000 * 10 / 100));

                        detailRequest.setTotalVerifyPrice(total);
                        detailRequest.setRemark("奖励3万+高级代理的10%+标准代理的5%");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 4L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(80000));
                        detailRequest.setRemark("奖励8万");
                    }
                }

                detailRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
                detailRequest.setDelFlag(DelFlagEnum.NO.getValue());
                detailRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
                detailRequest.setCreateUser(1L);
                sysAdminVerifyDetailMapper.save(detailRequest);
            }
        }
    }

    private BigDecimal calculatePersonLevel0(AdminVo verifyAdmin, Long adminLevel) {
        // 商户推广
        List<AdminVo> childAdmins = adminMapper.findAllAdminsByParentIdAndAuditStatus(verifyAdmin.getId(), AuditStatusEnums.VERIFY_SUCCESS.getValue());
        BigDecimal retTotal = new BigDecimal("0");
        for (AdminVo admin : childAdmins) {
            SysAdminVerifyDetailVo verifyDetailVo = sysAdminVerifyDetailMapper.getUseAdminVerifyDetailByObjectIdAndVerifyType(verifyAdmin.getId(), admin.getId(), VerifyTypeEnums.PERSON_VERIFY.getValue());
            if (ObjectUtil.isEmpty(verifyDetailVo)) {
                SysAdminVerifyDetailRequest detailRequest = new SysAdminVerifyDetailRequest();
                // 普通代理
                if (ObjectUtil.equal(adminLevel, 1L)) {
                    if (ObjectUtil.equal(admin.getAdminLevel(), 1L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(0));
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 2L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(20000));
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 3L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(30000));
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 4L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(80000));
                    }
                    // 标准代理
                } else if (ObjectUtil.equal(adminLevel, 2L)) {
                    if (ObjectUtil.equal(admin.getAdminLevel(), 1L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(0));
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 2L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(20000));
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 3L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(30000));
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 4L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(80000));
                    }
                    // 高级代理
                } else if (ObjectUtil.equal(adminLevel, 3L)) {
                    if (ObjectUtil.equal(admin.getAdminLevel(), 1L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(0));
                        detailRequest.setRemark("奖励0元");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 2L)) {
                        List<AdminVo> child2Admins = adminMapper.findAllAdminsByParentIdAndAuditStatus(admin.getId(), AuditStatusEnums.VERIFY_SUCCESS.getValue());
                        Integer count = 0;
                        for (AdminVo child2 : child2Admins) {
                            SysAdminVerifyDetailVo verifyDetail2Vo = sysAdminVerifyDetailMapper.getUseAdminVerifyDetailByObjectIdAndVerifyType(verifyAdmin.getId(), admin.getId(), VerifyTypeEnums.PERSON_VERIFY.getValue());
                            if ((ObjectUtil.isEmpty(verifyDetail2Vo)) && ObjectUtil.equal(child2.getAdminLevel(), 2L)) {
                                ++count;
                            }
                        }
                        BigDecimal total = new BigDecimal(20000).add(new BigDecimal(count * 20000 * 10 / 100));
                        detailRequest.setTotalVerifyPrice(total);
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 3L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(30000));
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 4L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(80000));
                    }
                    // 至尊代理
                } else if (ObjectUtil.equal(adminLevel, 4L)) {
                    if (ObjectUtil.equal(admin.getAdminLevel(), 1L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(0));
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 2L)) {
                        List<AdminVo> child2Admins = adminMapper.findAllAdminsByParentIdAndAuditStatus(admin.getId(), AuditStatusEnums.VERIFY_SUCCESS.getValue());
                        Integer count = 0;
                        for (AdminVo child2 : child2Admins) {
                            SysAdminVerifyDetailVo verifyDetail2Vo = sysAdminVerifyDetailMapper.getUseAdminVerifyDetailByObjectIdAndVerifyType(verifyAdmin.getId(), admin.getId(), VerifyTypeEnums.PERSON_VERIFY.getValue());
                            if ((ObjectUtil.isEmpty(verifyDetail2Vo)) && ObjectUtil.equal(child2.getAdminLevel(), 2L)) {
                                ++count;
                            }
                        }
                        BigDecimal total = new BigDecimal(20000).add(new BigDecimal(count * 20000 * 10 / 100));
                        detailRequest.setTotalVerifyPrice(total);
                        detailRequest.setRemark("奖励2万+标准代理的10%");
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 3L)) {
                        List<AdminVo> child2Admins = adminMapper.findAllAdminsByParentIdAndAuditStatus(admin.getId(), AuditStatusEnums.VERIFY_SUCCESS.getValue());
                        Integer bzcount = 0;
                        Integer gjcount = 0;
                        for (AdminVo child2 : child2Admins) {
                            SysAdminVerifyDetailVo verifyDetail2Vo = sysAdminVerifyDetailMapper.getUseAdminVerifyDetailByObjectIdAndVerifyType(verifyAdmin.getId(), admin.getId(), VerifyTypeEnums.PERSON_VERIFY.getValue());
                            if ((ObjectUtil.isEmpty(verifyDetail2Vo)) && ObjectUtil.equal(child2.getAdminLevel(), 2L)) {
                                ++bzcount;
                            }
                            if ((ObjectUtil.isEmpty(verifyDetail2Vo)) && ObjectUtil.equal(child2.getAdminLevel(), 3L)) {
                                ++gjcount;
                            }
                        }
                        BigDecimal total = new BigDecimal(30000).add(new BigDecimal(bzcount * 20000 * 5 / 100 + gjcount * 30000 * 10 / 100));
                        detailRequest.setTotalVerifyPrice(total);
                    } else if (ObjectUtil.equal(admin.getAdminLevel(), 4L)) {
                        detailRequest.setTotalVerifyPrice(new BigDecimal(80000));
                    }
                }
                retTotal = retTotal.add(detailRequest.getTotalVerifyPrice());
            }
        }

        return retTotal;
    }

    /**
     * 删除核销数据 和 核销明细
     *
     * @param request
     * @param verifyAdmin
     */
    private void deleteVerifyAndVerifyDetail(SysAdminVerifyRequest request, AdminVo verifyAdmin) {
        SysAdminVerifyVo sysAdminVerifyVo = sysAdminVerifyMapper.getModelByAdminIdAndVerifyMonth(verifyAdmin.getId(), request.getVerifyMonth());
        // 删除核销记录
        if (ObjectUtil.isNotEmpty(sysAdminVerifyVo)) {
            sysAdminVerifyMapper.realDeleteById(sysAdminVerifyVo.getId());
            sysAdminVerifyDetailMapper.realDeleteByVerifyId(sysAdminVerifyVo.getId());
            adminVerifyDetailOrderMapper.realDeleteByVerifyId(sysAdminVerifyVo.getId());
        }
    }

    private void deleteVerifyAndVerifyYearDetail(SysAdminVerifyRequest request, AdminVo verifyAdmin) {
        SysAdminVerifyVo sysAdminVerifyVo = sysAdminVerifyMapper.getModelByAdminIdAndVerifyYear(verifyAdmin.getId(), request.getVerifyYear());
        // 删除核销记录
        if (ObjectUtil.isNotEmpty(sysAdminVerifyVo)) {
            sysAdminVerifyMapper.realDeleteById(sysAdminVerifyVo.getId());
            sysAdminVerifyDetailMapper.realDeleteByVerifyId(sysAdminVerifyVo.getId());
            adminVerifyDetailOrderMapper.realDeleteByVerifyId(sysAdminVerifyVo.getId());
        }
    }

    /**
     * 计算商户卡项记录
     *
     * @param request
     * @param verifyAdmin
     * @param adminVerifyRequest
     * @param proxyMechanismVo
     */
    private void calculateShopCardLog(SysAdminVerifyRequest request, AdminVo verifyAdmin, SysAdminVerifyRequest adminVerifyRequest, ProxyMechanismVo proxyMechanismVo) {
        // 季度返现
        BigDecimal k3 = proxyMechanismVo.getKf3Money();
        BigDecimal k6 = proxyMechanismVo.getKf6Money();
        BigDecimal k12 = proxyMechanismVo.getKf12Money();

        List<ShopCardLogVo> adminCards = shopCardLogMapper.findCurrentMonthVerifySuccessShopCardLogs(verifyAdmin.getId(), request.getVerifyMonth());
        adminCards.forEach(card -> {
            SysAdminVerifyDetailRequest detailRequest = new SysAdminVerifyDetailRequest();
            detailRequest.setVerifyId(adminVerifyRequest.getId());
            detailRequest.setAdminId(verifyAdmin.getId());
            detailRequest.setObjectId(card.getId() + "");
            detailRequest.setVerifyType(VerifyTypeEnums.SHOP_VERIFY.getValue());
            detailRequest.setTotalPrice(card.getCardPrice());
            // 此处时间应该从retail_shop_card中获取，此处直接写死
            if (ObjectUtil.equal(card.getCardType(), 1L)) {
                detailRequest.setRemark("季卡");
                detailRequest.setTotalVerifyPrice(card.getCardPrice().multiply(k3).divide(new BigDecimal(100)));
            } else if (ObjectUtil.equal(card.getCardType(), 2L)) {
                detailRequest.setRemark("半年卡");
                detailRequest.setTotalVerifyPrice(card.getCardPrice().multiply(k6).divide(new BigDecimal(100)));
            } else if (ObjectUtil.equal(card.getCardType(), 3L)) {
                detailRequest.setRemark("年卡");
                detailRequest.setTotalVerifyPrice(card.getCardPrice().multiply(k12).divide(new BigDecimal(100)));
            }

            detailRequest.setVerifyTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
            detailRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
            detailRequest.setDelFlag(DelFlagEnum.NO.getValue());
            detailRequest.setCreateUser(1L);

            sysAdminVerifyDetailMapper.save(detailRequest);
        });
    }

    private BigDecimal calculateShopCardLog0(String verifyMonth, AdminVo verifyAdmin, ProxyMechanismVo proxyMechanismVo) {
        // 季度返现
        BigDecimal k3 = proxyMechanismVo.getKf3Money();
        BigDecimal k6 = proxyMechanismVo.getKf6Money();
        BigDecimal k12 = proxyMechanismVo.getKf12Money();
        BigDecimal total = new BigDecimal("0");
        List<ShopCardLogVo> adminCards = shopCardLogMapper.findCurrentMonthVerifySuccessShopCardLogs(verifyAdmin.getId(), verifyMonth);
        for (ShopCardLogVo card : adminCards) {// 此处时间应该从retail_shop_card中获取，此处直接写死
            if (ObjectUtil.equal(card.getCardType(), 1L)) {
                total = total.add(card.getCardPrice().multiply(k3).divide(new BigDecimal(100)));
            } else if (ObjectUtil.equal(card.getCardType(), 2L)) {
                total = total.add(card.getCardPrice().multiply(k6).divide(new BigDecimal(100)));
            } else if (ObjectUtil.equal(card.getCardType(), 3L)) {
                total = total.add(card.getCardPrice().multiply(k12).divide(new BigDecimal(100)));
            }
        }
        return total;
    }

    private BigDecimal calculateShopCardLog1(String verifyMonth, AdminVo verifyAdmin, ProxyMechanismVo proxyMechanismVo) {
        // 季度返现
        BigDecimal k3 = proxyMechanismVo.getKf3Money();
        BigDecimal k6 = proxyMechanismVo.getKf6Money();
        BigDecimal k12 = proxyMechanismVo.getKf12Money();
        BigDecimal total = new BigDecimal("0");
        List<ShopCardLogVo> adminCards = shopCardLogMapper.findCurrentMonthVerifySuccessShopCardLogsDay(verifyAdmin.getId(), verifyMonth);
        for (ShopCardLogVo card : adminCards) {// 此处时间应该从retail_shop_card中获取，此处直接写死
            if (ObjectUtil.equal(card.getCardType(), 1L)) {
                total = total.add(card.getCardPrice().multiply(k3).divide(new BigDecimal(100)));
            } else if (ObjectUtil.equal(card.getCardType(), 2L)) {
                total = total.add(card.getCardPrice().multiply(k6).divide(new BigDecimal(100)));
            } else if (ObjectUtil.equal(card.getCardType(), 3L)) {
                total = total.add(card.getCardPrice().multiply(k12).divide(new BigDecimal(100)));
            }
        }
        return total;
    }

    private SysAdminVerifyRequest saveAdminVerifyRequest(SysAdminVerifyRequest request, RetailWxGetMoneyVo wxGetMoney, AdminVo verifyAdmin) {
        SysAdminVerifyRequest adminVerifyRequest = new SysAdminVerifyRequest();
        adminVerifyRequest.setAdminId(verifyAdmin.getId());
        if (ObjectUtil.equal(request.getVerifyType(), 2)) {
            adminVerifyRequest.setVerifyYear(request.getVerifyYear());
        } else if (ObjectUtil.equal(request.getVerifyType(), 1)) {
            String verifyMonth = request.getVerifyMonth();
            if (ObjectUtil.isNotEmpty(verifyMonth)) {
                adminVerifyRequest.setVerifyYear(verifyMonth.split("-")[0]);
            }
        }
        adminVerifyRequest.setVerifyType(request.getVerifyType());
        adminVerifyRequest.setVerifyMonth(request.getVerifyMonth());
        adminVerifyRequest.setAdminLevel(verifyAdmin.getAdminLevel());
        adminVerifyRequest.setTotalPrice(null);
        adminVerifyRequest.setTotalVerifyPrice(null);
        adminVerifyRequest.setWechatPer(wxGetMoney.getGetMoneyPer());
        adminVerifyRequest.setWechatPrice(null);
        adminVerifyRequest.setExamineVerify(ExamineVerifyEnums.SHEN_HE_TONGGUO.getValue());
        adminVerifyRequest.setExamineVerifyRemark("系统核销:" + (request.getVerifyType() == 2 ? "年度" : "月度"));
        adminVerifyRequest.setExamineVerifyTime(new Date());
        adminVerifyRequest.setTixianFlag(TiXianFlagEnums.DAI_TI_XIAN.getValue());
        adminVerifyRequest.setTixianTime(null);
        adminVerifyRequest.setTixianRemark("");
        adminVerifyRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
        adminVerifyRequest.setDelFlag(DelFlagEnum.NO.getValue());
        adminVerifyRequest.setCreateUser(1L);
        sysAdminVerifyMapper.save(adminVerifyRequest);
        return adminVerifyRequest;
    }

    /**
     * 插入核销推送信息
     *
     * @param vo
     */
    private void insertVerifyMsg(SysAdminVerifyVo vo, Integer verifyType) {
        // 插入记录数据
        RetailMsgRequest request = new RetailMsgRequest();
        request.setMsgType(MsgTypeEnums.VERIF_MSG.getValue());
        StringBuffer stringBuffer = new StringBuffer();

        if (ObjectUtil.equal(verifyType, 1)) {
//            stringBuffer.append("月度核销数据\n");
            stringBuffer.append("核销日期：" + vo.getVerifyMonth() + "\n");
        } else if (ObjectUtil.equal(verifyType, 2)) {
//            stringBuffer.append("年度核销数据\n");
            stringBuffer.append("核销日期：" + vo.getVerifyYear() + "\n");
        }

        stringBuffer.append("总金额：" + ObjectUtil.defaultIfNull(vo.getTotalPrice(), "0") + "\n");
        stringBuffer.append("核销金额：" + ObjectUtil.defaultIfNull(vo.getTotalVerifyPrice(), 0) + "\n");
        stringBuffer.append("提现手续费(%)：" + ObjectUtil.defaultIfNull(vo.getWechatPrice(), 0) + "\n");
        stringBuffer.append("提现金额：" + ObjectUtil.defaultIfNull(vo.getVerifyPrice(), 0));

        request.setMsgContent(stringBuffer.toString());
        request.setMsgUser(vo.getAdminId() + "");
        request.setDelFlag(DelFlagEnum.NO.getValue());
        request.setStatusFlag(StatusFlagEnum.USE.getValue());
        request.setCreateUser(1L);
        request.setRemark("核销推送");
        Long id = retailMsgService.save(request);
        retailMsgService.delayMsg(id);
    }


    @Override
    public List<SysAdminVerifyVo> getList(Long userId) {
        List<SysAdminVerifyVo> list = sysAdminVerifyMapper.getList(userId);
        list.forEach(l -> {
            l.setTixianFlagName(TiXianFlagEnums.getStatusValues(l.getTixianFlag()));
            ProxyMechanismCategoryVo vo = proxyMechanismCategoryMapper.getModel(l.getAdminLevel());
            l.setAdminLevelName(vo.getCategoryName());
            l.setVerifyTypeName(l.getVerifyType() == 1 ? "月度" : "年度");
        });
        return list;
    }

    @Override
    public AdminIncomePersonVo statisticsIncomePerson(Long id) {
        AdminIncomePersonVo adminIncomePersonVo = sysAdminVerifyMapper.statisticsIncomePerson(id);
        inComePersonMonth(id, adminIncomePersonVo);
        inComePersonMonthDay(id, adminIncomePersonVo);
        return adminIncomePersonVo;
    }

    @Override
    public List<SysAdminVerifyVo> findVerifyList(Integer verifyType, String verifyDate, Integer examineVerify, Integer tixianFlag) {
        return sysAdminVerifyMapper.findVerifyList(verifyDate, verifyType, examineVerify, tixianFlag);
    }

    private void inComePersonMonthDay(Long id, AdminIncomePersonVo adminIncomePersonVo) {
        String verifyMonthDay = DateUtil.format(new Date(), "yyyy-MM-dd");
        AdminVo verifyAdmin = adminMapper.getModel(id);
        Long adminLevel = verifyAdmin.getAdminLevel();
        BigDecimal total = new BigDecimal("0");
        // 代理业绩
        if (adminLevel > 1) {
            ProxyMechanismVo proxyMechanismVo = proxyMechanismMapper.getModelByProxyLevel(adminLevel);
            // 商户订单推广
            total = total.add(calculateShopCardLog1(verifyMonthDay, verifyAdmin, proxyMechanismVo));
            // 代理等级计算
//            total = total.add(calculatePersonLevel0(verifyAdmin, adminLevel));
            // 月度奖励
            total = total.add(calculateOrderMonth1(verifyMonthDay, verifyAdmin, adminLevel));
        } else {
            Long retUpgradeLevel = verifyAdmin.getUpgradeLevel();
            if (ObjectUtil.isNotEmpty(retUpgradeLevel)) {
                AdminUpgradeConfigVo adminUpgradeConfigVo = adminUpgradeConfigMapper.getModel(retUpgradeLevel);
                total = total.add(calculateYwyOrderMonth1(verifyAdmin, adminUpgradeConfigVo, verifyMonthDay));
            }
            total = total.add(calculateTuijianYwyMonth1(verifyAdmin, verifyMonthDay));
        }

        adminIncomePersonVo.setDayEstimatePrice(total.doubleValue() + "");
    }

    private void inComePersonMonth(Long id, AdminIncomePersonVo adminIncomePersonVo) {
        String verifyMonth = DateUtil.format(new Date(), "yyyy-MM");
        AdminVo verifyAdmin = adminMapper.getModel(id);
        Long adminLevel = verifyAdmin.getAdminLevel();
        BigDecimal total = new BigDecimal("0");
        // 代理业绩
        if (adminLevel > 1) {
            ProxyMechanismVo proxyMechanismVo = proxyMechanismMapper.getModelByProxyLevel(adminLevel);
            // 商户订单推广
            total = total.add(calculateShopCardLog0(verifyMonth, verifyAdmin, proxyMechanismVo));
            // 代理等级计算
            total = total.add(calculatePersonLevel0(verifyAdmin, adminLevel));
            // 月度奖励
            total = total.add(calculateOrderMonth0(verifyMonth, verifyAdmin, adminLevel));
        } else {
            Long retUpgradeLevel = verifyAdmin.getUpgradeLevel();
            if (ObjectUtil.isNotEmpty(retUpgradeLevel)) {
                AdminUpgradeConfigVo adminUpgradeConfigVo = adminUpgradeConfigMapper.getModel(retUpgradeLevel);
                total = total.add(calculateYwyOrderMonth0(verifyAdmin, adminUpgradeConfigVo, verifyMonth));
            }
            total = total.add(calculateTuijianYwyMonth0(verifyAdmin, verifyMonth));
        }

        adminIncomePersonVo.setEstimatePrice(total.doubleValue() + "");
    }
}
